﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameEnter : MonoBehaviour, IGameEnterControl
{
    public GameEnterState.GameState NextState {
        get => (null == CurrGameState) ? GameEnterState.GameState.INIT : CurrGameState.NextGameState;
    }

    public GameEnterState CurrGameState { get; private set; } = null;
    public List<string> Files { get; set; } = null;

    private void Start()
    {
        // do some init

        // start init game asset
        PlayNext();
    }

    private GameEnterState[] gameEnterStates = new GameEnterState[(int)GameEnterState.GameState.MAX];
    public void PlayNext()
    {
        GameEnterState.GameState state = NextState;
        int index = (int)state;
        CurrGameState = gameEnterStates[index];
        if(null == CurrGameState) {
            switch (state) {
                case GameEnterState.GameState.LOADZIP:
                    CurrGameState = new GameEnterStateLoadZip(this);
                    break;
                case GameEnterState.GameState.UNZIP:
                    CurrGameState = new GameEnterStateUnzip(this);
                    break;
                case GameEnterState.GameState.LOADBUNDLE:
                    CurrGameState = new GameEnterStateLoadBundle(this);
                    break;
                case GameEnterState.GameState.UPDATE:
                    CurrGameState = new GameEnterStateUpdate(this);
                    break;
                case GameEnterState.GameState.START:
                    CurrGameState = new GameEnterStateStart(this);
                    break;
                case GameEnterState.GameState.MAX:
                case GameEnterState.GameState.NONE:
                case GameEnterState.GameState.INIT:
                    CurrGameState = new GameEnterStateInit(this);
                    break;
            }
            gameEnterStates[index] = CurrGameState;
        }
        CurrGameState.Start();
    }

    private void Update()
    {
        if (Input.GetKeyUp(KeyCode.C)) {
            UIManager.Instance.ShowWindow<TestWindow>();
        } else if (Input.GetKeyUp(KeyCode.L)) {
            EngineFramework.LoadScene();
            // AssetsLoadManager.Instance.Clear();
            // AssetsPoolManager.Instance.ClearCache();
        }
    }
}
